import 'dart:convert';
import 'request.dart';


class JMNetResponse {
  dynamic data;
  JMNetRequest? request;
  int? code;
  String? msg;
  String? extra;
  String? url;
  bool get isOk => (code == 1);

  JMNetResponse({
    this.data,
    this.request,
    this.code,
    this.msg,
    this.extra,
    this.url,
  });

  @override
  String toString() {
    var dataStr = '';
    if (data is Map) {
      dataStr = json.encode(data);
    } else {
      dataStr = data.toString();
    }

    var reqParamsStr = request?.params.toString();
    var reqHeadersStr = request?.headers().toString();
    var reqStr = '{params:$reqParamsStr,headers:$reqHeadersStr}';
    return '{request:$reqStr,code:$code,msg:$msg,data:$dataStr,extra:$extra}';
  }
}
